<template>
  <div>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="部门名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="introduce"
        label="部门描述"
        width="280">
      </el-table-column>
      <el-table-column
        prop="manager"
        label="部门经理"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="部门电话">
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="sizes, prev, pager, next"
      :page-sizes="[5, 10, 20, 50]"
      :total="total"
      align = 'right'
      @current-change = "goPage"
      @size-change = "goPageSize">
    </el-pagination>
  </div>
</template>

<script>
// 引入mock文件
import dept from '../js/dept/dept.js'
import axios from "axios";
// 引入axios文件 main文件中已经引入了
// import axios from 'axios'

export default {
  name: 'dept',
  data () {
    return {
      tableData:[],
      pageSize:5,
      currentPage:1,
      total:0
    }
  },
  mounted() {
    this.loadAll()
  },
  methods:{
    goPage(currentPage){
      this.currentPage = currentPage;
      console.log('当前页码' + currentPage);
      this.loadAll();
    },
    goPageSize(pageSize){
      this.pageSize = pageSize;
      this.currentPage = 1;
      console.log('当前页码' + this.currentPage);
      console.log('每页展示条数' + pageSize);
      this.loadAll();
    },

    loadAll(){
      axios.post("/dept/loadAll",{"currentPage":this.currentPage,"pageSize":this.pageSize})
        .then(result=>{
          this.tableData = result.data.data;
          this.total = result.data.totals;
        })
        .catch(error=>{
          console.log(error);
          alert("系统繁忙，请稍后再试")
        })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>



